/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MazeSolver.java
 *
 * Created on Jan 2, 2010, 8:51:27 AM
 */

package gamaze;

/**
 *
 * @author pborrego
 */
public class MazeSolver extends javax.swing.JFrame {

    /** Creates new form MazeSolver */
    public MazeSolver() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        mazeViewer1 = new gamaze.MazeViewer();
        pnlControls = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        pnlMaze = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        spnrWidth = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        spnrHeight = new javax.swing.JSpinner();
        jPanel7 = new javax.swing.JPanel();
        btnGenerate = new javax.swing.JButton();
        pnalGA = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        spnrPopSize = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        spnrMutationRate = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        spnrMaxGen = new javax.swing.JSpinner();
        jPanel6 = new javax.swing.JPanel();
        btnStartStop = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 540, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 411, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setPreferredSize(new java.awt.Dimension(600, 400));
        jPanel1.setLayout(new java.awt.BorderLayout());

        org.jdesktop.layout.GroupLayout mazeViewer1Layout = new org.jdesktop.layout.GroupLayout(mazeViewer1);
        mazeViewer1.setLayout(mazeViewer1Layout);
        mazeViewer1Layout.setHorizontalGroup(
            mazeViewer1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 814, Short.MAX_VALUE)
        );
        mazeViewer1Layout.setVerticalGroup(
            mazeViewer1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 820, Short.MAX_VALUE)
        );

        jPanel1.add(mazeViewer1, java.awt.BorderLayout.CENTER);
        jPanel1.revalidate();

        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.PAGE_AXIS));

        pnlMaze.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.PAGE_AXIS));

        jPanel10.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("Maze Options");
        jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jPanel10.add(jLabel6);

        jPanel5.add(jPanel10);

        jPanel8.setLayout(new java.awt.GridLayout(0, 2, 2, 5));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Width:");
        jPanel8.add(jLabel1);

        spnrWidth.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(10), Integer.valueOf(0), null, Integer.valueOf(1)));
        jPanel8.add(spnrWidth);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Height:");
        jPanel8.add(jLabel2);

        spnrHeight.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(10), Integer.valueOf(0), null, Integer.valueOf(1)));
        jPanel8.add(spnrHeight);

        jPanel5.add(jPanel8);

        btnGenerate.setText("Generate Maze");
        btnGenerate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerateActionPerformed(evt);
            }
        });
        jPanel7.add(btnGenerate);

        jPanel5.add(jPanel7);

        pnlMaze.add(jPanel5);

        jPanel3.add(pnlMaze);

        pnalGA.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.PAGE_AXIS));

        jPanel11.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Genetic Algorithm Options");
        jPanel11.add(jLabel7);

        jPanel2.add(jPanel11);

        jPanel9.setLayout(new java.awt.GridLayout(0, 2, 2, 5));

        jLabel4.setText("Population Size:");
        jPanel9.add(jLabel4);

        spnrPopSize.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(20), Integer.valueOf(1), null, Integer.valueOf(1)));
        jPanel9.add(spnrPopSize);

        jLabel5.setText("Mutation Rate:");
        jPanel9.add(jLabel5);

        spnrMutationRate.setModel(new javax.swing.SpinnerNumberModel(0.0010d, 0.0d, 1.0d, 0.0010d));
        jPanel9.add(spnrMutationRate);

        jLabel3.setText("Max Generations:");
        jPanel9.add(jLabel3);

        spnrMaxGen.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(5000), Integer.valueOf(1), null, Integer.valueOf(1)));
        jPanel9.add(spnrMaxGen);

        jPanel2.add(jPanel9);

        btnStartStop.setText("Start");
        jPanel6.add(btnStartStop);

        btnReset.setText("Reset");
        jPanel6.add(btnReset);

        jPanel2.add(jPanel6);

        pnalGA.add(jPanel2);

        jPanel3.add(pnalGA);

        pnlControls.add(jPanel3);

        jPanel1.add(pnlControls, java.awt.BorderLayout.EAST);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1006, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed
        this.mazeViewer1.renderMaze(Integer.valueOf(spnrWidth.getValue().toString()),
                Integer.valueOf(spnrHeight.getValue().toString()));
        this.mazeViewer1.validate();
        this.mazeViewer1.repaint();
    }//GEN-LAST:event_btnGenerateActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MazeSolver ms = new MazeSolver();
                ms.pack();
                ms.setSize(600,400);
                ms.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGenerate;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnStartStop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private gamaze.MazeViewer mazeViewer1;
    private javax.swing.JPanel pnalGA;
    private javax.swing.JPanel pnlControls;
    private javax.swing.JPanel pnlMaze;
    private javax.swing.JSpinner spnrHeight;
    private javax.swing.JSpinner spnrMaxGen;
    private javax.swing.JSpinner spnrMutationRate;
    private javax.swing.JSpinner spnrPopSize;
    private javax.swing.JSpinner spnrWidth;
    // End of variables declaration//GEN-END:variables

}
